@echo off
chcp 65001
setlocal enabledelayedexpansion

echo 根据Tomcat 10的兼容性要求，将所有代码文件中的"jakarta"替换为"javax"，或者将所有的"javax"替换为"jakarta"。输入1或2选择替换方向：:
echo 1. Tomcat 9 及以下版本，替换 "jakarta" 为 "javax"
echo 2. Tomcat 10 以上版本，替换 "javax" 为 "jakarta"
set /p option="输入你的选择: "

set "search="
set "replace="

if "%option%"=="1" (
    set "search=jakarta"
    set "replace=javax"
) else if "%option%"=="2" (
    set "search=javax"
    set "replace=jakarta"
) else (
    echo Invalid option
    exit /b 1
)

echo Replacing "%search%" with "%replace%" in all .java files...

for /R %%F in (*.java) do (
    for /F "delims=" %%L in (%%F) do (
        set "line=%%L"
        set "line=!line:%search%=%replace%!"
        echo !line!>>"%%F.tmp"
    )
    move /Y "%%F.tmp" "%%F" >nul
)

echo Done.

endlocal